# 给定一个数组 nums，编写一个函数将所有 0 移动到数组的末尾，同时保持非零元素的相对顺序。
#
#  示例 1：
# 输入：nums = [0,1,0,3,12]
# 输出：[1,3,12,0,0]
#
#  示例 2：
# 输入：nums = [0]
# 输出：5, nums = [0]
from typing import List


class Solution:
    def moveZeroes(self, nums: List[int]) -> None:
        """
        Do not return anything, modify nums in-place instead.
        """
        # 将非零部分"移到"数组前面
        notZeroLen = 0
        for index in range(len(nums)):
            if nums[index] != 0:
                nums[notZeroLen] = nums[index]
                notZeroLen += 1
        # 将后面全部置 0
        while notZeroLen < len(nums):
            nums[notZeroLen] = 0
            notZeroLen += 1


if __name__ == "__main__":
    nums = [0, 0, 1, 1, 1, 2, 2, 3, 3, 4]
    # nums = [1, 1, 1]
    # nums = [1, 1]
    print(Solution().moveZeroes(nums))
    print(nums)
